<template>
  <div class="a">
  <div class="top">
    <router-link to='/' active-class="set">首页</router-link>
    <div class="title" v-show="this.$store.state.username">欢迎  {{this.$store.state.username}}  进入</div>
    <router-link to='/login' v-show="!this.$store.state.username">登录</router-link>
    <router-link to='/register' v-show="!this.$store.state.username">注册</router-link>
    <a href="/" >注销</a>
  </div>
  </div>
</template>

<script>
import pubsub from 'pubsub-js';
export default {
  name: "topPage",
  data(){
    return{
      username:''
    }
  },
  mounted() {
    pubsub.subscribe('send',(msgName,msg)=>{
      console.log(msgName+":"+msg)
      this.username = msg
      this.$store.state.username = msg
    })
  }
}
</script>

<style scoped>
.a{
  display: flex;
  justify-content: center;
  height: 5rem;
  background-color: rgba(255, 255, 255, 0.3);
}
.a:hover{
  background-color: rgba(248, 246, 246, 0.6);
}

.top {
  width: 96%;
  height: 96%;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  text-align: center;
}
.set{
  background-color: rgba(255, 255, 255, 0.71);
}
.top>a {
  text-decoration: none;
  display: inline-block;
  color: black;
  font-size: 1.2rem;
  font-weight: 100;
  line-height: 5rem;
  width: 9rem;

}
.top>a:hover{
  background-color: rgba(255, 255, 255, 0.3);
}
.title{
  width: 300px;
  height: 50px;
  background-color: transparent;
  font-size: 20px;
  margin-top: 20px;
  color: rgba(12, 136, 213, 0.54);
  margin-left:610px;
}
</style>